def quicksort(list):
    if len(list) < 2:
        return list
    prev = []
    end = []
    pivot = list[0]
    for item in list[1:]:
        if item < pivot:
            prev.append(item)
        elif item > pivot:
            end.append(item)
    return quicksort(prev) + [pivot] + quicksort(end)

print quicksort([3, 5, 2, 1, 4])